/**
 * 分类管理和属性管理相关接口
 */
import api from '@/utils/request';

// ==================== 分类管理 ====================

/**
 * 获取分类类型枚举列表
 */
export const getCategoryTypes = (showLoading = true) =>
  api.get('/erp/systemConfig/item/CATEGORY_TYPE', {}, showLoading);

/**
 * 获取分类分页列表
 */
export const getCategoryList = (params, showLoading = true) =>
  api.post('/item-center/category/page', params, showLoading);

/**
 * 根据分类编码查询分类详情
 */
export const getCategoryDetail = (code, showLoading = true) =>
  api.get(`/item-center/category/detail/${code}`, {}, showLoading);

/**
 * 查询父级分类列表（用于下拉等场景）
 */
export const getParentCategoryList = (params, showLoading = true) =>
  api.get('/item-center/category/parent', params, showLoading);

/**
 * 新增分类
 */
export const addCategory = (data, showLoading = true) =>
  api.post('/item-center/category/add', data, showLoading);

/**
 * 更新分类
 */
export const updateCategory = (data, showLoading = true) =>
  api.post('/item-center/category/update', data, showLoading);

/**
 * 启用/禁用分类状态
 */
export const toggleCategoryStatus = (data, showLoading = true) =>
  api.post('/item-center/category/enable', data, showLoading);

/**
 * 导出分类数据
 */
export const exportCategory = (params) =>
  api.post('/item-center/category/export', params, false, 'blob');

/**
 * 删除分类与属性的关联
 */
export const deleteCategoryPropertyRelation = (id, showLoading = true) =>
  api.get(
    `/item-center/category/itemCategoryPropertyRelation/delete/${id}`,
    {},
    showLoading
  );

/**
 * categoryManagement 模块导出
 */
export const categoryAPI = {
  getCategoryTypes,
  getCategoryList,
  getCategoryDetail,
  getParentCategoryList,
  addCategory,
  updateCategory,
  toggleCategoryStatus,
  exportCategory,
  deleteCategoryPropertyRelation,
};

export default categoryAPI;
